<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>React学习 | 小马の博客</title><meta name="keywords" content="React   学习"><meta name="author" content="Kun Kun"><meta name="copyright" content="Kun Kun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="本笔记为本人系统学习 React 阶段笔记-观看尚硅谷2021版React技术全家桶全套完整版 整理而成&gt;  React 系统学习笔记 一、React 简介   官网链接:中文官网  介绍描述  用于动态构建用户界面的 JavaScript(只关注视图)  由 Facebook 开源   2、插件   FeHelper json 格式化 (谷歌)   1、React 的特点   声明式编程">
<meta property="og:type" content="article">
<meta property="og:title" content="React学习">
<meta property="og:url" content="https://ma_jinkun.gitee.io/2021/12/29/react/React-one/index.html">
<meta property="og:site_name" content="小马の博客">
<meta property="og:description" content="本笔记为本人系统学习 React 阶段笔记-观看尚硅谷2021版React技术全家桶全套完整版 整理而成&gt;  React 系统学习笔记 一、React 简介   官网链接:中文官网  介绍描述  用于动态构建用户界面的 JavaScript(只关注视图)  由 Facebook 开源   2、插件   FeHelper json 格式化 (谷歌)   1、React 的特点   声明式编程">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg">
<meta property="article:published_time" content="2021-12-29T09:24:15.000Z">
<meta property="article:modified_time" content="2022-01-05T03:18:59.517Z">
<meta property="article:author" content="Kun Kun">
<meta property="article:tag" content="React   学习">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://ma_jinkun.gitee.io/2021/12/29/react/React-one/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'React学习',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-01-05 11:18:59'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/css/main.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiperstyle.css"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s2.loli.net/2021/12/28/uBIDZUEFrpsCvH7.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音樂</span></a></div><div class="menus_item"><a class="site-page" href="/contact/"><i class="fa-fw far fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s2.loli.net/2021/12/30/OjiswQgfeP3Jm4S.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小马の博客</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音樂</span></a></div><div class="menus_item"><a class="site-page" href="/contact/"><i class="fa-fw far fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">React学习</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-12-29T09:24:15.000Z" title="发表于 2021-12-29 17:24:15">2021-12-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-01-05T03:18:59.517Z" title="更新于 2022-01-05 11:18:59">2022-01-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/React-%E5%AD%A6%E4%B9%A0/">React  学习</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="React学习"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>本笔记为本人系统学习 React 阶段笔记-观看<code>尚硅谷2021版React技术全家桶全套完整版</code> 整理而成&gt;</p>
</blockquote>
<h1 id="React-系统学习笔记"><a href="#React-系统学习笔记" class="headerlink" title="React 系统学习笔记"></a>React 系统学习笔记</h1><hr>
<h1 id="一、React-简介"><a href="#一、React-简介" class="headerlink" title="一、React 简介"></a>一、React 简介</h1><blockquote>
<ol>
<li> 官网链接:<a target="_blank" rel="noopener" href="https://react.docschina.org/">中文官网</a></li>
<li> 介绍描述</li>
<li> 用于动态构建用户界面的 JavaScript(只关注视图)</li>
<li> 由 Facebook 开源</li>
</ol>
</blockquote>
<h3 id="2、插件"><a href="#2、插件" class="headerlink" title="2、插件"></a>2、插件</h3><blockquote>
<ol>
<li> FeHelper json 格式化 (谷歌)</li>
</ol>
</blockquote>
<h3 id="1、React-的特点"><a href="#1、React-的特点" class="headerlink" title="1、React 的特点"></a>1、React 的特点</h3><blockquote>
<ol>
<li><p> 声明式编程</p>
</li>
<li><p> 组件化编程</p>
</li>
<li><p>React Native 编写原生应用</p>
<p> <em>React Native (简称 RN)是 Facebook 于 2015 年 4 月开源的跨平台移动应用开发框架，是 Facebook 早先开源的 JS 框架 React 在原生移动应用平台的衍生产物</em></p>
</li>
<li><p> 高效 (优秀的 Diffing 算法)</p>
</li>
</ol>
</blockquote>
<h3 id="2、React-高效的原因"><a href="#2、React-高效的原因" class="headerlink" title="2、React 高效的原因"></a>2、React 高效的原因</h3><blockquote>
<ol>
<li> 使用虚拟(virtual)DOM,不总是直接操作页面真实 DON</li>
<li> DOM Diffing 算法,最小化页面重绘</li>
<li> <code>注意</code>：React 并不会提高渲染速度,反而可能会增加渲染时间,真正高效的原因是它能有效<code>减少渲染次数</code></li>
</ol>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.创建虚拟DOM,创建嵌套格式的doms</span></span><br><span class="line"><span class="keyword">const</span> VDOM = React.createElement(</span><br><span class="line">  <span class="string">&quot;h1&quot;</span>,</span><br><span class="line">  &#123; <span class="attr">id</span>: <span class="string">&quot;title&quot;</span> &#125;,</span><br><span class="line">  React.createElement(<span class="string">&quot;span&quot;</span>, &#123;&#125;, <span class="string">&quot;hello,React&quot;</span>)</span><br><span class="line">);</span><br><span class="line"><span class="comment">//2.渲染虚拟DOM到页面</span></span><br><span class="line">ReactDOM.render(VDOM, docoment.getElementById(<span class="string">&quot;test&quot;</span>));</span><br></pre></td></tr></table></figure>

<blockquote>
<p>可以看到，上下两种方式，明显<code>jsx</code>的写法更符合我们的习惯,当出现多重嵌套时,js 创建方法会使我们编程出现很大麻烦</p>
<p>但是 jsx 其实也只是帮我们做了一层编译,当我们写完 jsx 代码后,最终我们的代码也会被编译成 js 的书写方式</p>
</blockquote>
<h3 id="4、关于虚拟-DOM"><a href="#4、关于虚拟-DOM" class="headerlink" title="4、关于虚拟 DOM"></a>4、关于虚拟 DOM</h3><blockquote>
<ol>
<li> 本质时 Object 类型的对象(一般对象)</li>
<li> 虚拟 DOM 比较’轻’,真实 DOM 比较’重’,因为虚拟 DOM 是 React 内部在用,无需真实 DOM 上那么多的属性(只有 React 需要的属性)</li>
<li> 虚拟 DOM 最终会被 React 转化为真实 DOM,呈现在页面上</li>
</ol>
</blockquote>
<h2 id="二、jsx-语法规则"><a href="#二、jsx-语法规则" class="headerlink" title="二、jsx 语法规则"></a>二、jsx 语法规则</h2><blockquote>
<p>JSX 是一种 JavaScript 的语法扩展、是一种嵌入式的类似 XML 的语法,常应用于 React 架构中,但也不仅限于此.应该说 JSX 因 React 框架而流行,但也存在其他的实现.只要你够厉害,甚至能在单片机上实现(当然你要自己写出它的实现方式)</p>
</blockquote>
<h3 id="1、规则"><a href="#1、规则" class="headerlink" title="1、规则"></a>1、规则</h3><blockquote>
<ol>
<li> 定义虚拟 DOM 时,不要写引号</li>
<li> 标签中混入 JS 表达式时要用{}</li>
<li> 样式的类名指定不要用 class,要用 className</li>
<li> 内联样式,要用 <code>style=&#123;&#123;key:value&#125;&#125;的形式(双&#123;&#125;代表对象,单&#123;&#125;代表表达式)</code> 去写</li>
<li> 只有一个跟标签(整个虚拟 DOM 在外层有且仅有一个容器包裹)</li>
<li> 标签必须闭合</li>
<li> 标签首字母</li>
</ol>
<p>若<code>小写字母开头</code>,则将该标签转为 html 中同名元素,若 html 中无该标签对应的同名元素,则<code>报错</code></p>
<p>若<code>大写字母开头</code>,ract 就去渲染对应组件,若组件没有定义,则<code>报错</code></p>
</blockquote>
<h3 id="2、区分【js-语句-代码-】与【js-表达式】"><a href="#2、区分【js-语句-代码-】与【js-表达式】" class="headerlink" title="2、区分【js 语句(代码)】与【js 表达式】"></a>2、区分【js 语句(代码)】与【js 表达式】</h3><blockquote>
<ol>
<li> 表达式:一个表达式会产生一个值,可以放在任何一个需要值的地方</li>
</ol>
<p>下面这些都是表达式</p>
<ol>
<li><p>a</p>
</li>
<li><p>a+b</p>
</li>
<li><p>demo(1)</p>
</li>
<li><p>arr.map()</p>
</li>
<li><p>function test(){}</p>
</li>
<li><p>语句:不能放在创建虚拟 dom 语句中</p>
</li>
<li><p>if(){}</p>
</li>
<li><p>for(){}</p>
</li>
<li><p>switch(){}</p>
</li>
</ol>
</blockquote>
<h2 id="三、两种组件定义区别、组件与模块理解"><a href="#三、两种组件定义区别、组件与模块理解" class="headerlink" title="三、两种组件定义区别、组件与模块理解"></a>三、两种组件定义区别、组件与模块理解</h2><h3 id="Ⅰ-react-中定义组件"><a href="#Ⅰ-react-中定义组件" class="headerlink" title="Ⅰ-react 中定义组件"></a>Ⅰ-react 中定义组件</h3><h5 id="①-函数式声明组件"><a href="#①-函数式声明组件" class="headerlink" title="① 函数式声明组件"></a>① 函数式声明组件</h5><blockquote>
<p>执行了 ReactDOM.render(<MyComponent/>…….之后，发生了什么？</p>
<p>1.React 解析组件标签，找到了 MyComponent 组件。</p>
<p>2.发现组件是使用函数定义的，随后调用该函数，将返回的虚拟 DOM 转为真实 DOM，随后呈现在页面中。</p>
</blockquote>
<h5 id="②-类式组件-下面的实例都是指类组件"><a href="#②-类式组件-下面的实例都是指类组件" class="headerlink" title="② 类式组件(下面的实例都是指类组件)"></a>② 类式组件(下面的实例都是指类组件)</h5><blockquote>
<p>执行了 ReactDOM.render(<MyComponent/>…….之后，发生了什么？</p>
<p>​ 1.React 解析组件标签，找到了 MyComponent 组件。</p>
<p>​ 2.发现组件是使用类定义的，随后 new 出来该类的实例，并通过该实例调用到原型上的 render 方法。</p>
<p>​ 3.将 render 返回的虚拟 DOM 转为真实 DOM，随后呈现在页面中。</p>
<p>组件中的 render 是放在哪里的？</p>
<p>​ MyComponent 的原型对象上，供实例使用。</p>
<p>组件中的 render 中的 this 是谁？</p>
<p>​ MyComponent 的实例对象 &lt;=&gt; MyComponent 组件实例对象。</p>
</blockquote>
<h3 id="Ⅱ-模块与模块化"><a href="#Ⅱ-模块与模块化" class="headerlink" title="Ⅱ-模块与模块化"></a>Ⅱ-模块与模块化</h3><h5 id="①-模块"><a href="#①-模块" class="headerlink" title="① 模块"></a>① 模块</h5><blockquote>
<ol>
<li> 理解:向外提供特定功能的 js 程序,一般就是一个 js 文件</li>
<li> 为什么要拆成模块:随着业务逻辑增加,代码越来越多且复杂</li>
<li> 作用:复用 js,提高 js 运行效率 一句话形容简化 js</li>
</ol>
</blockquote>
<h5 id="②-模块化"><a href="#②-模块化" class="headerlink" title="② 模块化"></a>② 模块化</h5><blockquote>
<p>当应用的 js 都以模块来编写,这个应用就是一个模块化的应用</p>
</blockquote>
<h3 id="Ⅲ-组件与组件化"><a href="#Ⅲ-组件与组件化" class="headerlink" title="Ⅲ-组件与组件化"></a>Ⅲ-组件与组件化</h3><h5 id="①-组件"><a href="#①-组件" class="headerlink" title="① 组件"></a>① 组件</h5><blockquote>
<ol>
<li><p> 理解:用来实现局部功能效果的代码和资源的集合(html/css/js/img 等等)</p>
</li>
<li><p> 为什么要用组件:一个界面的功能复杂</p>
</li>
<li><p> 作用:复用编码,简化项目编码,提高运行效率</p>
</li>
</ol>
</blockquote>
<h5 id="②-组件化"><a href="#②-组件化" class="headerlink" title="② 组件化"></a>② 组件化</h5><blockquote>
<p>当应用是以多组件的方式实现,这个应用就是组件化的应用</p>
</blockquote>
<h2 id="四、React面向组件编程"><a href="#四、React面向组件编程" class="headerlink" title="四、React面向组件编程"></a>四、React面向组件编程</h2><blockquote>
<ol>
<li>使用React开发者工具调试</li>
</ol>
<p>  <code>React Developer Tools</code></p>
<ol start="2">
<li>注意</li>
</ol>
<p>  a) 组件名必须是首字母大写</p>
<p>  b) 虚拟DOM元素只能有一个根元素</p>
<p>  c) 虚拟DOM元素必须有结束标签 &lt; /&gt;</p>
<ol start="3">
<li>渲染类组件标签的基本流程</li>
</ol>
<p>  a) React内部会创建组件实例对象</p>
<p>  b) 调用render()得到虚拟DOM,并解析为真实DOM</p>
<p>  c) 插入到指定的页面元素内部</p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Kun Kun</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://ma_jinkun.gitee.io/2021/12/29/react/React-one/">https://ma_jinkun.gitee.io/2021/12/29/react/React-one/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://ma_jinkun.gitee.io" target="_blank">小马の博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/React-%E5%AD%A6%E4%B9%A0/">React   学习</a></div><div class="post_share"><div class="social-share" data-image="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/12/30/react/react-two/"><img class="prev-cover" src="[&quot;https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg&quot;]" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">React第二天(组件三大属性)</div></div></a></div><div class="next-post pull-right"><a href="/2021/12/29/hexo-Write/"><img class="next-cover" src="https://cdn.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">如何用hexo写文章</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s2.loli.net/2021/12/28/uBIDZUEFrpsCvH7.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Kun Kun</div><div class="author-info__description">嘘,别看,眼睛会疼！</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">7</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/xxxxx" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:2583931485@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="qq:2583931485" target="_blank" title="QQ"><i class="fab fa-qq"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">基于Hexo 主题butterfly 开发的</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#React-%E7%B3%BB%E7%BB%9F%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0"><span class="toc-number">1.</span> <span class="toc-text">React 系统学习笔记</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80%E3%80%81React-%E7%AE%80%E4%BB%8B"><span class="toc-number">2.</span> <span class="toc-text">一、React 简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E6%8F%92%E4%BB%B6"><span class="toc-number">2.0.1.</span> <span class="toc-text">2、插件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81React-%E7%9A%84%E7%89%B9%E7%82%B9"><span class="toc-number">2.0.2.</span> <span class="toc-text">1、React 的特点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81React-%E9%AB%98%E6%95%88%E7%9A%84%E5%8E%9F%E5%9B%A0"><span class="toc-number">2.0.3.</span> <span class="toc-text">2、React 高效的原因</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81%E5%85%B3%E4%BA%8E%E8%99%9A%E6%8B%9F-DOM"><span class="toc-number">2.0.4.</span> <span class="toc-text">4、关于虚拟 DOM</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E3%80%81jsx-%E8%AF%AD%E6%B3%95%E8%A7%84%E5%88%99"><span class="toc-number">2.1.</span> <span class="toc-text">二、jsx 语法规则</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E8%A7%84%E5%88%99"><span class="toc-number">2.1.1.</span> <span class="toc-text">1、规则</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E5%8C%BA%E5%88%86%E3%80%90js-%E8%AF%AD%E5%8F%A5-%E4%BB%A3%E7%A0%81-%E3%80%91%E4%B8%8E%E3%80%90js-%E8%A1%A8%E8%BE%BE%E5%BC%8F%E3%80%91"><span class="toc-number">2.1.2.</span> <span class="toc-text">2、区分【js 语句(代码)】与【js 表达式】</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E4%B8%A4%E7%A7%8D%E7%BB%84%E4%BB%B6%E5%AE%9A%E4%B9%89%E5%8C%BA%E5%88%AB%E3%80%81%E7%BB%84%E4%BB%B6%E4%B8%8E%E6%A8%A1%E5%9D%97%E7%90%86%E8%A7%A3"><span class="toc-number">2.2.</span> <span class="toc-text">三、两种组件定义区别、组件与模块理解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E2%85%A0-react-%E4%B8%AD%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6"><span class="toc-number">2.2.1.</span> <span class="toc-text">Ⅰ-react 中定义组件</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E5%87%BD%E6%95%B0%E5%BC%8F%E5%A3%B0%E6%98%8E%E7%BB%84%E4%BB%B6"><span class="toc-number">2.2.1.0.1.</span> <span class="toc-text">① 函数式声明组件</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E7%B1%BB%E5%BC%8F%E7%BB%84%E4%BB%B6-%E4%B8%8B%E9%9D%A2%E7%9A%84%E5%AE%9E%E4%BE%8B%E9%83%BD%E6%98%AF%E6%8C%87%E7%B1%BB%E7%BB%84%E4%BB%B6"><span class="toc-number">2.2.1.0.2.</span> <span class="toc-text">② 类式组件(下面的实例都是指类组件)</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E2%85%A1-%E6%A8%A1%E5%9D%97%E4%B8%8E%E6%A8%A1%E5%9D%97%E5%8C%96"><span class="toc-number">2.2.2.</span> <span class="toc-text">Ⅱ-模块与模块化</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E6%A8%A1%E5%9D%97"><span class="toc-number">2.2.2.0.1.</span> <span class="toc-text">① 模块</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E6%A8%A1%E5%9D%97%E5%8C%96"><span class="toc-number">2.2.2.0.2.</span> <span class="toc-text">② 模块化</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E2%85%A2-%E7%BB%84%E4%BB%B6%E4%B8%8E%E7%BB%84%E4%BB%B6%E5%8C%96"><span class="toc-number">2.2.3.</span> <span class="toc-text">Ⅲ-组件与组件化</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A0-%E7%BB%84%E4%BB%B6"><span class="toc-number">2.2.3.0.1.</span> <span class="toc-text">① 组件</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E2%91%A1-%E7%BB%84%E4%BB%B6%E5%8C%96"><span class="toc-number">2.2.3.0.2.</span> <span class="toc-text">② 组件化</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9B%E3%80%81React%E9%9D%A2%E5%90%91%E7%BB%84%E4%BB%B6%E7%BC%96%E7%A8%8B"><span class="toc-number">2.3.</span> <span class="toc-text">四、React面向组件编程</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/01/04/react-ly/" title="React路由"><img src="[&quot;https://image-tupss.test.upcdn.net/baner.png&quot;]" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React路由"/></a><div class="content"><a class="title" href="/2022/01/04/react-ly/" title="React路由">React路由</a><time datetime="2022-01-04T06:28:11.000Z" title="发表于 2022-01-04 14:28:11">2022-01-04</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/30/react/react-proxy/" title="React 配置代理"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React 配置代理"/></a><div class="content"><a class="title" href="/2021/12/30/react/react-proxy/" title="React 配置代理">React 配置代理</a><time datetime="2021-12-30T02:14:13.000Z" title="发表于 2021-12-30 10:14:13">2021-12-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/30/react/react-cycle/" title="React(生命周期,脚手架)"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React(生命周期,脚手架)"/></a><div class="content"><a class="title" href="/2021/12/30/react/react-cycle/" title="React(生命周期,脚手架)">React(生命周期,脚手架)</a><time datetime="2021-12-30T01:58:45.000Z" title="发表于 2021-12-30 09:58:45">2021-12-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/30/react/react-two/" title="React第二天(组件三大属性)"><img src="[&quot;https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg&quot;]" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React第二天(组件三大属性)"/></a><div class="content"><a class="title" href="/2021/12/30/react/react-two/" title="React第二天(组件三大属性)">React第二天(组件三大属性)</a><time datetime="2021-12-30T01:49:08.000Z" title="发表于 2021-12-30 09:49:08">2021-12-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/29/react/React-one/" title="React学习"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="React学习"/></a><div class="content"><a class="title" href="/2021/12/29/react/React-one/" title="React学习">React学习</a><time datetime="2021-12-29T09:24:15.000Z" title="发表于 2021-12-29 17:24:15">2021-12-29</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By Kun Kun</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>function history_calendar_injector_config(){
                var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
                var item_html = '<div class="card-widget card-history"><div class="card-content"><div class="item-headline"><i class="fas fa-clock fa-spin"></i><span>那年今日</span></div><div id="history-baidu" style="height: 100px;overflow: hidden"><div class="history_swiper-container" id="history-container" style="width: 100%;height: 100%"><div class="swiper-wrapper" id="history_container_wrapper" style="height:20px"></div></div></div></div>';
                console.log('已挂载history_calendar')
                // parent_div_git.innerHTML=item_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",item_html) // 有报错，但不影响使用(支持pjax跳转)
            }if( document.getElementsByClassName('sticky_layout')[0] && (location.pathname ==='all'|| 'all' ==='all')){

            history_calendar_injector_config()
        } </script><script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-card-history/baiduhistory/js/main.js"></script> <script data-pjax>if(document.getElementById('recent-posts') && location.pathname =='/'){
    
    var parent = document.getElementById('recent-posts');
    var child = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-28</span><a class="blog-slider__title" href="2021/12/28/My-First-Artical/">第一次测试文档</a><div class="blog-slider__text">简单好用的 hexo 博客文章置顶插件！</div><a class="blog-slider__button" href="2021/12/28/My-First-Artical/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://image-tupss.test.upcdn.net/baner.png" alt="https://image-tupss.test.upcdn.net/baner.png"/></div><div class="blog-slider__content"><span class="blog-slider__code">2022-01-04</span><a class="blog-slider__title" href="2022/01/04/react-ly/">React路由</a><div class="blog-slider__text">React路由！</div><a class="blog-slider__button" href="2022/01/04/react-ly/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-30</span><a class="blog-slider__title" href="2021/12/30/react/react-cycle/">React(生命周期,脚手架)</a><div class="blog-slider__text">生命周期 脚手架！</div><a class="blog-slider__button" href="2021/12/30/react/react-cycle/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-30</span><a class="blog-slider__title" href="2021/12/30/react/react-proxy/">React 配置代理</a><div class="blog-slider__text">配置代理！</div><a class="blog-slider__button" href="2021/12/30/react/react-proxy/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg" alt="https://s2.loli.net/2022/01/05/ezb8QtqIdmLEShW.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-30</span><a class="blog-slider__title" href="2021/12/30/react/react-two/">React第二天(组件三大属性)</a><div class="blog-slider__text">第二天！</div><a class="blog-slider__button" href="2021/12/30/react/react-two/">详情</a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms"><div class="blog-slider__img"><img src="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg" alt="https://s2.loli.net/2021/12/28/Al7LXsN2hYH4icO.jpg"/></div><div class="blog-slider__content"><span class="blog-slider__code">2021-12-29</span><a class="blog-slider__title" href="2021/12/29/react/React-one/">React学习</a><div class="blog-slider__text">第一天！</div><a class="blog-slider__button" href="2021/12/29/react/React-one/">详情</a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载swiper')
    parent.insertAdjacentHTML("afterbegin",child)}
     </script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper/swiper/swiper.min.js"></script>
<script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-swiper@0.18/swiper/swiperindex.js"></script>
<style></style><!-- hexo injector body_end end --></body></html>